/**
 * Created by fu.
 * Date: 12-4-12
 * Time: 上午11:18
 */
var ajax=(function(){
        var xhr=null;
        try{xhr= new XMLHttpRequest();}catch(e){
            try{ xhr= new ActiveXObject('Msxml2.XMLHTTP'); }catch(e){
                try{ xhr= new ActiveXObject('Microsoft.XMLHTTP');}catch(e){
                }
            }
        }
        var seral=function(obj){
            var s='';
            if(typeof obj=='object'){
                for(var key in obj){
                    s+=key+'='+obj[key]+'&'
                }
            }
            return s;
        };
    return {
        get:function(url,arg,fn){
            url+=seral(arg);
            xhr.onreadystatechange=function(){
                if (xhr.readyState==4 && xhr.status==200){
                    fn(xhr.responseText);
                }
            };
            xhr.open('get',url,true);
            xhr.send(null);

        },
        post:function(url,arg,fn){

            xhr.onreadystatechange=function(){
                if (xhr.readyState==4 && xhr.status==200){
                    fn(xhr.responseText);
                }
            };
            xhr.open('post',url,true);
            xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
            xhr.send(seral(arg));
        }

    }


})();